package dbhandelling;


/*
 * This class establishes a connection from derby database.
 * It also provides a statement object so that querries can be exceuted on the data base 
 */

import java.sql.*;

public class Connections
{	
	
	private static Connection myConnection;
	private static Statement myStatement;

	
	
	
	/*
	 * Connections Constructor, here the new statement object is formed.
	 */
	
	
	public Connections()
	{
		try 
		{
			
			
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}
	
	
	// This static method loads the driver and should be called only once at the begining of
	// app execution.
	
	
	
	public static void loadDriver()
	{
		try 
		{
			Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}
	
	
	//  connects from db
	
	
	public static void connect()
	{
		try 
		{
			myConnection=DriverManager.getConnection("jdbc:derby:F:/Universal;");
			myStatement=myConnection.createStatement();	
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	}
	
	
	// diconncect from db
	
	public static Connection getMyConnection() {
		return myConnection;
	}


	public static Statement getMyStatement() {
		return myStatement;
	}


	public static void disConnect()
	{
		try
		{
			myConnection.close();
			myStatement=null;
		} 
		catch (SQLException e)
		{
			e.printStackTrace();
		}
	}
	
}
